package com.common.kafka;

import com.common.base.BaseEnum;
import com.common.exception.BaseException;
import com.common.util.MsgSendUtil;
import com.common.vo.MessageLogVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @version: V1.0
 * @author: szw
 * @className: DataPushApi
 * @packageName: DataPushApi
 * @description: 统一业务发送消息类
 * @data: 2021-1-27
 **/
@Component
@PropertySource("classpath:ys.properties")
public class DataPushApi {

    @Value("${kafka.log.topic}")
    private String logTopic;

    @Value("${ys.core.url}")
    private String coreUrl;


    @Resource
    private MsgSendUtil msgSendUtil;

    /**
     * 发送日志消息到数据中心
     * @param mes
     */
    public void sendDataLog(Object mes){
        try{
            msgSendUtil.send(coreUrl,logTopic,mes);
        }catch (Exception e){
            throw new BaseException(BaseEnum.MESSAGE_SEND_IS_ERROR);
        }
    }

    /**
     * 异步发送日志消息到数据中心
     * @param mes
     */
    public void asyncSendDataLog(MessageLogVo mes){
        try{
            msgSendUtil.asyncSend(coreUrl,logTopic,mes);
        }catch (Exception e){
            throw new BaseException(BaseEnum.MESSAGE_SEND_IS_ERROR);
        }
    }

    /**
     * 发送新闻消息到数据中心
     * @param mes
     */
    public void sendNewsData(Object mes){
        try{
            msgSendUtil.send(coreUrl,logTopic,mes);
        }catch (Exception e){
            throw new BaseException(BaseEnum.MESSAGE_SEND_IS_ERROR);
        }
    }
}
